//
//  TTAccountTool.m
//  JackDeve
//
//  Created by 王奎卿 on 2017/5/13.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "TTAccountTool.h"

@implementation TTAccountTool

//取消订单
-(void )cancelDingDan:(NSString *)url{
    // 写请求对象
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    // 接收的输入类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    //post请求
    
    [manager POST:url parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"Success:%@",responseObject);
        
        NSDictionary *dic = (NSDictionary *)responseObject;
        if ([dic objectForKey:@"data"] != nil) {
            [SVProgressHUD showSuccessWithStatus:[dic objectForKey:@"msg"]];
            [SVProgressHUD dismissWithDelay:1.5];
            
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"post请求失败:%@", error);
    }];
    
}
/** 删除订单*/
- (void)deleteDingDan:(NSString *)url {
    // 写请求对象
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    // 接收的输入类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    //post请求
    [manager POST:url parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"Success:%@",responseObject);
        
        NSDictionary *dic = (NSDictionary *)responseObject;
        if ([dic objectForKey:@"data"] != nil) {
            
            [SVProgressHUD showErrorWithStatus:[dic objectForKey:@"errmsg"]];
            [SVProgressHUD dismissWithDelay:1.5];
            
        } else if ([dic objectForKey:@"errmsg"] != nil) {
            [SVProgressHUD showSuccessWithStatus:[dic objectForKey:@"errmsg"]];
            [SVProgressHUD dismissWithDelay:1.5];
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"post请求失败:%@", error);
    }];
}

/** 再来一单*/
- (void)againDingDan:(NSString *)url {
    // 写请求对象
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    // 接收的输入类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    //post请求
    [manager POST:url parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"Success:%@",responseObject);
        
        NSDictionary *dic = (NSDictionary *)responseObject;
        NSDictionary *data = [dic objectForKey:@"data"];
        if (data != nil) {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"dinnerId" object:[data objectForKey:@"diner_id"]];
        } else if ([dic objectForKey:@"errcode"] != nil) {
            NSString *statusStr = @"获取商户失败";
            [SVProgressHUD showErrorWithStatus:statusStr];
            [SVProgressHUD dismissWithDelay:1.5];
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"post请求失败:%@", error);
    }];
}


@end
